﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _00_Process
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //获取当前正则运行的进程
            Process[] pros = Process.GetProcesses();
            //打印所有进程的名称
            foreach (Process p in pros)
            {
                //打印进程名称与ID
                Console.WriteLine($"{p.Id}:{p.ProcessName}");
            }

            ////提示杀死指导进程
            //Console.WriteLine("请输入要杀死的进程ID:");
            //int id = Convert.ToInt32(Console.ReadLine());
            ////根据进程ID杀死进程
            //Process process = Process.GetProcessById(id);
            //process.Kill();

            //提示输入杀死指定名称的进程
            Console.WriteLine("请输入要杀死的进程名称:");
            string name = Console.ReadLine();
            //根据进程名称杀死进程
            Process[] processes = Process.GetProcessesByName(name);
            foreach (Process process in processes)
            {
                process.Kill();
            }


            Console.Read();
        }
    }
}
